home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / db / esm-3.1 / esm-3 / usr / local / sm / src / admin / shutserver.c < prev   
Encoding:
C/C++ Source or Header  |  1996-05-05  |  5.0 KB  |  178 lines

  1. /*
  2.  *   $RCSfile: shutserver.c,v $  
  3.  *   $Revision: 1.1.1.1 $  
  4.  *   $Date: 1996/05/04 21:55:33 $      
  5.  */ 
  6. /**********************************************************************
  7. * EXODUS Database Toolkit Software
  8. * Copyright (c) 1991 Computer Sciences Department, University of
  9. *                    Wisconsin -- Madison
  10. * All Rights Reserved.
  11. *
  12. * Permission to use, copy, modify and distribute this software and its
  13. * documentation is hereby granted, provided that both the copyright
  14. * notice and this permission notice appear in all copies of the
  15. * software, derivative works or modified versions, and any portions
  16. * thereof, and that both notices appear in supporting documentation.
  17. *
  18. * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
  19. * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.  
  20. * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
  21. * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  22. *
  23. * The EXODUS Project Group requests users of this software to return 
  24. * any improvements or extensions that they make to:
  25. *
  26. *   EXODUS Project Group 
  27. *     c/o David J. DeWitt and Michael J. Carey
  28. *   Computer Sciences Department
  29. *   University of Wisconsin -- Madison
  30. *   Madison, WI 53706
  31. *
  32. *     or exodus@cs.wisc.edu
  33. *
  34. * In addition, the EXODUS Project Group requests that users grant the 
  35. * Computer Sciences Department rights to redistribute these changes.
  36. **********************************************************************/
  37.  
  38.  
  39. #include "sysdefs.h"
  40. #include "ess.h"
  41. #include "checking.h"
  42. #include "trace.h"
  43. #include "error.h"
  44. #include "list.h"
  45. #include "tid.h"
  46. #include "io.h"
  47. #include "lock.h"
  48. #include "object.h"
  49. #include "msgdefs.h"
  50. #include "adminmsg.h"
  51. #include "bf.h"
  52. #include "lsn.h"
  53. #include "loginfo.h"
  54. #include "load.h"
  55. #include "scan.h"
  56. #include "serverinfo.h"
  57. #include "sm_params.h"
  58. #include "btree.h"
  59. #include "msg_funcs.h"
  60. #include "sm_extfuncs.h"
  61. #include "sm_intfuncs.h"
  62. #include "sm_globals.h"
  63. #include "volume.h"
  64.  
  65. #define max_volumes 100
  66.  
  67. main (int argc, char** argv)
  68. {
  69.  
  70.     int            option;
  71.     VOLID        vols[max_volumes];
  72.     int            volCount = 0;
  73.     int            i;
  74.     int            e;
  75.     char        *errorMsg;
  76.  
  77.     TRPRINT(TR_ADMIN, TR_LEVEL_1, ("shutting down server"));
  78.  
  79.     /*
  80.      *  Read the default configuration files to have the bufpages
  81.      *  option set.
  82.      */
  83.     e = sm_ReadConfigFile(NULL, argv[0], &errorMsg);
  84.     if (e != esmNOERROR) {
  85.         fprintf(stderr, "Configuration file error: %s\n", errorMsg);
  86.         exit(0);
  87.     }
  88.  
  89.     /*
  90.      *  Set any options from the command line
  91.      */
  92.     e = sm_ParseCommandLine(&argc, argv, &errorMsg);
  93.     if (e != esmNOERROR) {
  94.         fprintf(stderr, "command line error: %s\n", errorMsg);
  95.         exit(0);
  96.     }
  97.  
  98.     i = 32; /* us a minimal buffer pool */
  99.     e = sm_SetClientOption("bufpages", &i, SM_int);
  100.     if (e != esmNOERROR) {
  101.         fprintf(stderr, "Could not set buffer pool option because: %s\n", sm_Error(sm_errno));
  102.         exit(1);
  103.     }
  104.  
  105.     /*
  106.      * Initialize the storage manager.
  107.      */
  108.     e = sm_Initialize();
  109.     if (e != esmNOERROR) {
  110.         fprintf(stderr, "Could not initialize the storage manager because: %s\n", sm_Error(sm_errno));
  111.         exit(1);
  112.     }
  113.  
  114.     /*
  115.      *  Evaluate command line options
  116.      */
  117.     while (( option = getopt(argc, argv, "v:ah")) != EOF) {
  118.         switch (option) {
  119.         case '?':
  120.             printf("Usage: %s [-a (for all known servers)] [-v volume_ID] [-h]\n", argv[0]);
  121.             exit(1);
  122.             break;
  123.         case 'a':
  124.             break;
  125.         case 'v':
  126.             vols[volCount] = atoi(optarg);
  127.             volCount++;
  128.             break;
  129.         case 'h':
  130.             printf("Usage: %s [-a (for all known servers)] [-v volume_ID] [-h]\n", argv[0]);
  131.             printf("    [-a] shutdown servers managing all known volumes\n");
  132.             printf("    [-v volume_ID] indicates that the server managing this volume\n");
  133.             printf("    up to %d -v options may be given\n", max_volumes);
  134.             exit(0);
  135.             break;
  136.         default:
  137.             SM_ERROR(TYPE_FATAL, esmINTERNAL);
  138.         }
  139.  
  140.         if (option == 'a') {
  141.             volCount = -1;
  142.             break;
  143.         }
  144.         if (volCount == max_volumes) {
  145.             printf("too many -v options -- max is %d\n", max_volumes);
  146.             exit(0);
  147.             break;
  148.         }
  149.     }
  150.  
  151.     /*
  152.      *  Make sure there were no extra arguments
  153.      */
  154.     if (optind != argc || (volCount == 0) ) {
  155.         printf("Usage: %s [-a (for all known servers)] [-v volume_ID] [-h]\n", argv[0]);
  156.         exit(1);
  157.     }
  158.  
  159.     
  160.     if (volCount < 0) {
  161.         printf("Shutting down all known servers\n");
  162.         if (sm_ShutdownServer( VOL_ALL, (VOLID) 0,
  163.             SHUT_ABORT_TRANS | SHUT_CLEAN_VOLUMES | SHUT_TAKE_CHECKPOINT) != esmNOERROR) {
  164.                 fprintf(stderr, "Shutting down all servers resulted in: %s\n", sm_Error(sm_errno));
  165.                 exit(1);
  166.         }
  167.     } else {
  168.         for (i = 0; i < volCount; i++) {
  169.             printf("Shutting down server for volume %d\n", (int) vols[i]);
  170.             if (sm_ShutdownServer( VOL_BY_VOLID, vols[i],
  171.                 SHUT_ABORT_TRANS | SHUT_CLEAN_VOLUMES | SHUT_TAKE_CHECKPOINT) != esmNOERROR) {
  172.                 fprintf(stderr, "Shutting down the server managing volume %d resulted in: %s\n", (int) vols[i], sm_Error(sm_errno));
  173.             }    
  174.         }
  175.     }
  176.     exit(0);
  177. }
  178.